package com.xinchuang.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xinchuang.comment.Constant;
import com.xinchuang.comment.R;
import com.xinchuang.domain.vo.MoldTypeVo;
import com.xinchuang.domain.vo.PartPriceVo;
import com.xinchuang.entity.MoldType;
import com.xinchuang.entity.PartMoldType;
import com.xinchuang.entity.PartPrice;
import com.xinchuang.mapper.MoldTypeMapper;
import com.xinchuang.mapper.PartMoldTypeMapper;
import com.xinchuang.role.entity.SystemHeader;
import com.xinchuang.service.IMoldTypeService;
import com.xinchuang.service.IPartMoldTypeService;
import com.xinchuang.service.IPartPriceService;
import com.xinchuang.service.MoldTypeModService;
import com.xinchuang.utils.MyUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.servlet.http.HttpServletRequest;
import java.io.FileNotFoundException;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Service
public class MoldTypeModServiceImpl implements MoldTypeModService {
    @Autowired
    private IMoldTypeService moldTypeService;

    @Autowired
    private IPartMoldTypeService partMoldTypeService;

    @Autowired
    private MoldTypeModService moldTypeModService;

    @Autowired
    private MoldTypeMapper moldTypeMapper;

    @Autowired
    private PartMoldTypeMapper partMoldTypeMapper;

    @Autowired
    private IPartPriceService partPriceService;

    @Override
    public String getMoldTypeList(JSONObject jsonObject) {
        //jsonobject解析获取页码
        String pageNum = jsonObject.getString("pageNum");
        //jsonobject解析获取模具类型Id
        String moldTypeId = jsonObject.getString("moldTypeId");
        Page<MoldType> moldTypePage = moldTypeMapper.selectPage(new Page<>(Integer.valueOf(pageNum), Constant.PAGE_SIZE), new LambdaUpdateWrapper<MoldType>().like(StringUtils.isNotEmpty(moldTypeId), MoldType::getMoldTypeName, moldTypeId).orderByDesc(MoldType::getCreateTime));
        List<MoldType> records = moldTypePage.getRecords();
        List<MoldTypeVo> moldTypeVoList = new ArrayList<>();
        for (MoldType moldType : records) {
            MoldTypeVo moldTypeVo = new MoldTypeVo();
            BeanUtil.copyProperties(moldType, moldTypeVo);
            List<PartMoldType> partMoldTypeList = partMoldTypeMapper.selectList(new LambdaUpdateWrapper<PartMoldType>().eq(PartMoldType::getMoldTypeId, moldType.getMoldTypeId()));
            moldTypeVo.setPartList(partMoldTypeList);
            moldTypeVoList.add(moldTypeVo);
        }

        JSONObject userInfoJson = new JSONObject();
        userInfoJson.put("dataList", moldTypeVoList);
        userInfoJson.put("totalNum", moldTypePage.getTotal());
        return JSON.toJSONString(R.data(userInfoJson));

    }

    @Override
    @Transactional
    public String saveMoldType(JSONObject jsonObject, HttpServletRequest request) {
        try {
            saveMoldTypeOrRollback(jsonObject, request);
        } catch (RuntimeException e) {
            return JSON.toJSONString(R.fail(e.getMessage()));
        }
        return JSON.toJSONString(R.success("保存成功"));
    }

    @Transactional
    public void saveMoldTypeOrRollback(JSONObject jsonObject, HttpServletRequest request) throws RuntimeException {
        //jsonobject解析获取模具类型名称
        String moldTypeName = jsonObject.getString("moldTypeName");
        //jsonobject解析获取模具类型Id
        String moldTypeId = jsonObject.getString("moldTypeId");
        //jsonobject解析获取零件列表
        //JSONArray partsList = jsonObject.getJSONArray("partsList");
        JSONArray idList = jsonObject.getJSONArray("partList");
        //jsonobject解析获取备用参数1
        String param1 = jsonObject.getString("param1");
        //jsonobject解析获取备用参数2
        String param2 = jsonObject.getString("param2");
        //jsonobject解析获取备用参数3
        String param3 = jsonObject.getString("param3");
        //jsonobject解析获取备用参数4
        String param4 = jsonObject.getString("param4");
        //jsonobject解析获取备用参数5
        String param5 = jsonObject.getString("param5");
        //jsonobject解析获取备用参数6
        String param6 = jsonObject.getString("param6");
        //jsonobject解析获取备用参数7
        String param7 = jsonObject.getString("param7");
        //jsonobject解析获取备用参数8
        String param8 = jsonObject.getString("param8");
        //jsonobject解析获取备用参数9
        String param9 = jsonObject.getString("param9");
        //获取创建人名字
        SystemHeader header = MyUtils.getHeader(request);
        String createBy = "";
        if (header.getId() != null) createBy = MyUtils.getName(header.getId());
        MoldType moldType = new MoldType();
        if (StringUtils.isNotEmpty(moldTypeId)) {
            moldType.setMoldTypeId(moldTypeId);
        }
        moldType.setCreateBy(createBy);
        moldType.setMoldTypeName(moldTypeName);
        moldType.setCreateTime(LocalDateTime.now());
        boolean bmoldType = moldTypeService.saveOrUpdate(moldType);
        if (!bmoldType) {
            throw new RuntimeException("模具类型保存失败");
        }
        moldTypeId = moldType.getMoldTypeId();
        for (int i = 0; i < idList.size(); i++) {
            JSONObject jsonObject1 = idList.getJSONObject(i);
            String partName = jsonObject1.getString("partName");
            String partId = jsonObject1.getString("partId");
            Boolean isMoldFrame = jsonObject1.getBoolean("isMoldFrame");
            Boolean isRequired = jsonObject1.getBoolean("isRequired");
            Boolean isMainMaterial = jsonObject1.getBoolean("isMainMaterial");
            Boolean isStandardCom = jsonObject1.getBoolean("isStandardCom");
            String constOfHeight = jsonObject1.getString("constOfHeight");
            String constOfLength = jsonObject1.getString("constOfLength");
            String constOfWidth = jsonObject1.getString("constOfWidth");
            String density = jsonObject1.getString("density");
            String id = jsonObject1.getString("id");
            String price = jsonObject1.getString("price");

            PartMoldType partMoldType = new PartMoldType();
            if (StringUtils.isNotEmpty(id)) {
                partMoldType.setId(id);
            } else {
                LambdaQueryWrapper<PartMoldType> wrapper = Wrappers.lambdaQuery();
                boolean exists = partMoldTypeMapper.exists(wrapper.eq(PartMoldType::getMoldTypeId, moldTypeId).eq(PartMoldType::getPartId, partId));
                if (exists) {
                    throw new RuntimeException("零件" + partName + "已存在");
                }
            }
            partMoldType.setMoldTypeId(moldTypeId);
            partMoldType.setPartName(partName);
            partMoldType.setIsMoldFrame(isMoldFrame);
            partMoldType.setIsRequired(isRequired);
            partMoldType.setDensity(density);
            partMoldType.setConstOfHeight(constOfHeight);
            partMoldType.setConstOfLength(constOfLength);
            partMoldType.setConstOfWidth(constOfWidth);
            partMoldType.setPrice(price);
            partMoldType.setPartId(partId);
            partMoldType.setIsMainMaterial(isMainMaterial);
            partMoldType.setIsStandardCom(isStandardCom);
            boolean bpartmoldType = partMoldTypeService.saveOrUpdate(partMoldType);
            if (!bpartmoldType) {
                throw new RuntimeException("零件" + partName + "保存失败");
            }
        }
    }

    @Override
    @Transactional
    public String deleteMoldType(JSONObject jsonObject) {
        //jsonobject解析获取ID列表
        JSONArray idList = jsonObject.getJSONArray("idList");
        int size = idList.size();
        if (size > 0) {
            int i = moldTypeMapper.deleteBatchIds(idList);
            if (i == size) {
                for (int j = 0; j < idList.size(); j++) {
                    partMoldTypeMapper.delete(new LambdaUpdateWrapper<PartMoldType>().eq(PartMoldType::getMoldTypeId, idList.get(j)));
                    if (j == idList.size() - 1) {
                        return JSON.toJSONString(R.success("删除成功"));
                    }
                }
            }

        }
        return JSON.toJSONString(R.fail("删除失败"));
    }

    @Override
    public String getPartListByTypeId(JSONObject jsonObject) {
        //jsonobject解析获取产品尺寸-高
        String height = jsonObject.getString("height");
        //jsonobject解析获取产品尺寸-宽
        String width = jsonObject.getString("width");
        //jsonobject解析获取产品尺寸-长
        String length = jsonObject.getString("length");
        //jsonobject解析获取模具类型Id
        String moldTypeId = jsonObject.getString("moldTypeId");
        //jsonobject解析获取模具编号
        String moldId = jsonObject.getString("moldId");
        //将获取到的长宽高转换为double
        double realLength = Double.parseDouble(length);
        double realWidth = Double.parseDouble(width);
        double readHeight = Double.parseDouble(height);
        //查询模具类型下的所包含的所有零件
        List<PartMoldType> partMoldTypes = partMoldTypeMapper.selectList(new LambdaQueryWrapper<PartMoldType>().eq(PartMoldType::getMoldTypeId, moldTypeId));
        if (partMoldTypes.size() == 0) return getEmptyList();
        //根据模具类型id查询模具类型名称
        String typeName;
        try {
            typeName = moldTypeMapper.selectOne(new LambdaQueryWrapper<MoldType>().eq(MoldType::getMoldTypeId, moldTypeId)).getMoldTypeName();
        } catch (Exception e) {
            return getEmptyList();
        }
        List<PartPriceVo> output = new ArrayList<>();
        List<PartPriceVo> outputOther = new ArrayList<>();
        //将所有的partMoldTypes存入map中
        Map<String, PartMoldType> map = new HashMap<>();
        for (PartMoldType partMoldType : partMoldTypes) {
            boolean flag = false;
            switch (partMoldType.getPartName()) {
                case "A板":
                case "B板":
                case "大直顶":
                case "大斜顶":
                case "流道板":
                case "顶针底板":
                case "顶针面板":
                case "面底板":
                case "模脚1":
                case "模脚2":
                    flag = true;
                    break;
            }
            if (flag) {
                map.put(partMoldType.getPartName(), partMoldType);
            } else {
                outputOther.add(PartPriceVo.partMoldType2PartPriceVo(partMoldType));
            }
        }
        //用来保存所有的PartPrice对象，方便获取其内容
        Map<String, PartPrice> mapPartPrice = new HashMap<>();
        //将结果封装到PartPrice列表中
        List<PartPrice> partPriceList = new ArrayList<>();
        //按照顺序给每个零件的长宽高以及质量赋值
        PartMoldType partMoldType = map.get("A板");
        PartPrice partPrice = setPartPrice(moldId, mapPartPrice, typeName, partMoldType, realLength, realWidth, readHeight);
        if (partPrice != null) {
            partPriceList.add(partPrice);
            PartPriceVo vo = new PartPriceVo();
            BeanUtils.copyProperties(partPrice, vo);
            output.add(vo);
        }
        partMoldType = map.get("B板");
        partPrice = setPartPrice(moldId, mapPartPrice, typeName, partMoldType, realLength, realWidth, readHeight);
        if (partPrice != null) {
            partPriceList.add(partPrice);
            PartPriceVo vo = new PartPriceVo();
            BeanUtils.copyProperties(partPrice, vo);
            output.add(vo);
        }
        partMoldType = map.get("大直顶");
        partPrice = setPartPrice(moldId, mapPartPrice, typeName, partMoldType, realLength, realWidth, readHeight);
        if (partPrice != null) {
            partPriceList.add(partPrice);
            PartPriceVo vo = new PartPriceVo();
            BeanUtils.copyProperties(partPrice, vo);
            output.add(vo);
        }
        partMoldType = map.get("大斜顶");
        partPrice = setPartPrice(moldId, mapPartPrice, typeName, partMoldType, realLength, realWidth, readHeight);
        if (partPrice != null) {
            partPriceList.add(partPrice);
            PartPriceVo vo = new PartPriceVo();
            BeanUtils.copyProperties(partPrice, vo);
            output.add(vo);
        }
        partMoldType = map.get("流道板");
        partPrice = setPartPrice(moldId, mapPartPrice, typeName, partMoldType, realLength, realWidth, readHeight);
        if (partPrice != null) {
            partPriceList.add(partPrice);
            PartPriceVo vo = new PartPriceVo();
            BeanUtils.copyProperties(partPrice, vo);
            output.add(vo);
        }
        partMoldType = map.get("顶针底板");
        partPrice = setPartPrice(moldId, mapPartPrice, typeName, partMoldType, realLength, realWidth, readHeight);
        if (partPrice != null) {
            partPriceList.add(partPrice);
            PartPriceVo vo = new PartPriceVo();
            BeanUtils.copyProperties(partPrice, vo);
            output.add(vo);
        }
        partMoldType = map.get("顶针面板");
        partPrice = setPartPrice(moldId, mapPartPrice, typeName, partMoldType, realLength, realWidth, readHeight);
        if (partPrice != null) {
            partPriceList.add(partPrice);
            PartPriceVo vo = new PartPriceVo();
            BeanUtils.copyProperties(partPrice, vo);
            output.add(vo);
        }
        partMoldType = map.get("面底板");
        partPrice = setPartPrice(moldId, mapPartPrice, typeName, partMoldType, realLength, realWidth, readHeight);
        if (partPrice != null) {
            partPriceList.add(partPrice);
            PartPriceVo vo = new PartPriceVo();
            BeanUtils.copyProperties(partPrice, vo);
            output.add(vo);
        }
        //不同类型的模具，模脚的相互依赖不同，分开判断
        if (typeName.equals("类似门板 背门，A B C柱本体等中型模具")) {
            partMoldType = map.get("模脚2");
            partPrice = setPartPrice(moldId, mapPartPrice, typeName, partMoldType, realLength, realWidth, readHeight);
            if (partPrice != null) {
                partPriceList.add(partPrice);
                PartPriceVo vo = new PartPriceVo();
                BeanUtils.copyProperties(partPrice, vo);
                output.add(vo);
            }
            partMoldType = map.get("模脚1");
            partPrice = setPartPrice(moldId, mapPartPrice, typeName, partMoldType, realLength, realWidth, readHeight);
            if (partPrice != null) {
                partPriceList.add(partPrice);
                PartPriceVo vo = new PartPriceVo();
                BeanUtils.copyProperties(partPrice, vo);
                output.add(vo);
            }
        } else if (typeName.equals("中小型模具")) {
            partMoldType = map.get("模脚1");
            partPrice = setPartPrice(moldId, mapPartPrice, typeName, partMoldType, realLength, realWidth, readHeight);
            if (partPrice != null) {
                partPriceList.add(partPrice);
                PartPriceVo vo = new PartPriceVo();
                BeanUtils.copyProperties(partPrice, vo);
                output.add(vo);
            }
        } else {
//            if (typeName.equals("保险杠本体大型模具") || typeName.equals("类似IP大型模具"))
            partMoldType = map.get("模脚1");
            partPrice = setPartPrice(moldId, mapPartPrice, typeName, partMoldType, realLength, realWidth, readHeight);
            if (partPrice != null) {
                partPriceList.add(partPrice);
                PartPriceVo vo = new PartPriceVo();
                BeanUtils.copyProperties(partPrice, vo);
                output.add(vo);
            }
            partMoldType = map.get("模脚2");
            partPrice = setPartPrice(moldId, mapPartPrice, typeName, partMoldType, realLength, realWidth, readHeight);
            if (partPrice != null) {
                partPriceList.add(partPrice);
                PartPriceVo vo = new PartPriceVo();
                BeanUtils.copyProperties(partPrice, vo);
                output.add(vo);
            }
        }
        //保存到part_price表中
        //partPriceService.saveOrUpdateBatch(partPriceList);
        JSONArray array = new JSONArray();
        array.addAll(output);
        array.addAll(outputOther);
        JSONObject jsonObject1 = new JSONObject();
        jsonObject1.put("partsList", array);
        return JSON.toJSONString(R.data(jsonObject1));
    }

    private String getEmptyList() {
        JSONArray array = new JSONArray();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("partsList", array);
        return JSON.toJSONString(R.data(jsonObject));
    }

    private void setPartPrice(Map<String, PartMoldType> map, String moldId, String typeName, double length, double width, double height) {

    }

    private PartPrice setPartPrice(String moldId, Map<String, PartPrice> mapPartPrice, String typeName, PartMoldType partMoldType, double length, double width, double height) {
        if (partMoldType != null) {
            double constOfLength = Double.parseDouble(partMoldType.getConstOfLength());
            double constOfWidth = Double.parseDouble(partMoldType.getConstOfWidth());
            double constOfHeight = Double.parseDouble(partMoldType.getConstOfHeight());
            double density = Double.parseDouble(partMoldType.getDensity());
            String partName = partMoldType.getPartName();
            Map<String, Double> params = setValues(mapPartPrice, typeName, partName, length, width, height, constOfLength, constOfWidth, constOfHeight, density);
            PartPrice partPrice = new PartPrice();
            BeanUtils.copyProperties(partMoldType, partPrice);
            //重量保留小数点后两位
            DecimalFormat format = new DecimalFormat("#.00");
            String finalWeight = format.format(params.get("weight"));
            partPrice.setLength(params.get("length").toString());
            partPrice.setWidth(params.get("width").toString());
            partPrice.setHeight(params.get("height").toString());
            partPrice.setMoldId(moldId);
            partPrice.setWeight(finalWeight);
            mapPartPrice.put(partName, partPrice);
            return partPrice;
        }
        return null;
    }

    private Map<String, Double> setValues(Map<String, PartPrice> mapPartPrice, String typeName, String partName, double length, double width, double height, double constantLength, double constantWidth, double constantHeight, double density) {
        double weight;
        if (typeName.equals("类似IP大型模具")) {
            switch (partName) {
                case "A板":
                    length += constantLength;
                    width += constantWidth;
                    height += constantHeight;
                    break;
                case "B板":
                    length += constantLength;
                    width += constantWidth;
                    height += constantHeight;
                    break;
                case "流道板":
                    length = Double.parseDouble(mapPartPrice.get("B板").getLength());
                    width = Double.parseDouble(mapPartPrice.get("B板").getWidth());
                    height = constantHeight;
                    break;
                case "顶针底板":
                    length += constantLength;
                    width += constantWidth;
                    height = constantHeight;
                    break;
                case "顶针面板":
                    length = Double.parseDouble(mapPartPrice.get("顶针底板").getLength());
                    width = Double.parseDouble(mapPartPrice.get("顶针底板").getWidth());
                    height = constantHeight;
                    break;
                case "面底板":
                    length = Double.parseDouble(mapPartPrice.get("A板").getLength()) + constantLength;
                    width = Double.parseDouble(mapPartPrice.get("A板").getWidth()) + constantLength;
                    height = constantHeight;
                    break;
                case "模脚1":
                    length = Double.parseDouble(mapPartPrice.get("B板").getWidth());
                    width = (Double.parseDouble(mapPartPrice.get("A板").getLength()) - Double.parseDouble(mapPartPrice.get("顶针底板").getLength())) / 2;
                    height = constantHeight;
                    break;
                case "模脚2":
                    length = Double.parseDouble(mapPartPrice.get("A板").getLength()) - Double.parseDouble(mapPartPrice.get("模脚1").getWidth()) * 2;
                    width = (Double.parseDouble(mapPartPrice.get("A板").getWidth()) - Double.parseDouble(mapPartPrice.get("顶针底板").getWidth())) / 2;
                    height = constantHeight;
                    break;
            }
        } else if (typeName.equals("类似门板 背门，A B C柱本体等中型模具")) {
            switch (partName) {
                case "A板":
                    length += constantLength;
                    width += constantWidth;
                    height += constantHeight;
                    break;
                case "B板":
                    length += constantLength;
                    width += constantWidth;
                    height += constantHeight;
                    break;
                case "流道板":
                    length = Double.parseDouble(mapPartPrice.get("B板").getLength());
                    width = Double.parseDouble(mapPartPrice.get("B板").getWidth());
                    height = constantHeight;
                    break;
                case "顶针底板":
                    length += constantLength;
                    width += constantWidth;
                    height = constantHeight;
                    break;
                case "顶针面板":
                    length = Double.parseDouble(mapPartPrice.get("顶针底板").getLength());
                    width = Double.parseDouble(mapPartPrice.get("顶针底板").getWidth());
                    height = constantHeight;
                    break;
                case "面底板":
                    length = Double.parseDouble(mapPartPrice.get("A板").getLength()) + constantLength;
                    width = Double.parseDouble(mapPartPrice.get("A板").getWidth()) + constantLength;
                    height = constantHeight;
                    break;
                case "模脚2":
                    length = Double.parseDouble(mapPartPrice.get("流道板").getWidth());
                    width = (Double.parseDouble(mapPartPrice.get("A板").getLength()) - Double.parseDouble(mapPartPrice.get("顶针底板").getLength())) / 2;
                    height = constantHeight;
                    break;
                case "模脚1":
                    length = Double.parseDouble(mapPartPrice.get("A板").getLength()) - Double.parseDouble(mapPartPrice.get("模脚2").getWidth()) * 2;
                    width = (Double.parseDouble(mapPartPrice.get("B板").getWidth()) - Double.parseDouble(mapPartPrice.get("顶针底板").getWidth())) / 2;
                    height = constantHeight;
                    break;
            }
        } else if (typeName.equals("中小型模具")) {
            switch (partName) {
                case "A板":
                    length += constantLength;
                    width += constantWidth;
                    height += constantHeight;
                    break;
                case "B板":
                    length += constantLength;
                    width += constantWidth;
                    height += constantHeight;
                    break;
                case "流道板":
                    length = Double.parseDouble(mapPartPrice.get("B板").getLength());
                    width = Double.parseDouble(mapPartPrice.get("B板").getWidth());
                    height = constantHeight;
                    break;
                case "顶针底板":
                    length += constantLength;
                    width += constantWidth;
                    height = constantHeight;
                    break;
                case "顶针面板":
                    length = Double.parseDouble(mapPartPrice.get("顶针底板").getLength());
                    width = Double.parseDouble(mapPartPrice.get("顶针底板").getWidth());
                    height = constantHeight;
                    break;
                case "面底板":
                    length = Double.parseDouble(mapPartPrice.get("A板").getLength()) + constantLength;
                    width = Double.parseDouble(mapPartPrice.get("A板").getWidth()) + constantLength;
                    height = constantHeight;
                    break;
                case "模脚1":
                    length = Double.parseDouble(mapPartPrice.get("A板").getLength());
                    width = (Double.parseDouble(mapPartPrice.get("B板").getWidth()) - Double.parseDouble(mapPartPrice.get("顶针底板").getWidth())) / 2;
                    height = constantHeight;
                    break;
            }
        } else {
            //保险杠本体大型模具 或 其他
            switch (partName) {
                case "A板":
                    length += constantLength;
                    width += constantWidth;
                    height += constantHeight;
                    break;
                case "B板":
                    length += constantLength;
                    width += constantWidth;
                    height = constantHeight + height / 3;
                    break;
                case "大直顶":
                    width = Double.parseDouble(mapPartPrice.get("A板").getWidth());
                    height = height * 3 / 4;
                    break;
                case "大斜顶":
                    length = width + constantLength;
                    height = height * 2 / 3 + constantHeight;
                    width = height / 2;
                    break;
                case "流道板":
                    length = Double.parseDouble(mapPartPrice.get("B板").getLength());
                    width = Double.parseDouble(mapPartPrice.get("B板").getWidth());
                    height = constantHeight;
                    break;
                case "顶针底板":
                    length += constantLength;
                    width += constantWidth;
                    height = constantHeight;
                    break;
                case "顶针面板":
                    length = Double.parseDouble(mapPartPrice.get("顶针底板").getLength());
                    width = Double.parseDouble(mapPartPrice.get("顶针底板").getWidth());
                    height = constantHeight;
                    break;
                case "面底板":
                    length = Double.parseDouble(mapPartPrice.get("A板").getLength()) + constantLength;
                    width = Double.parseDouble(mapPartPrice.get("A板").getWidth()) + constantWidth;
                    height = constantHeight;
                    break;
                case "模脚1":
                    length = Double.parseDouble(mapPartPrice.get("B板").getWidth());
                    width = (Double.parseDouble(mapPartPrice.get("A板").getLength()) - Double.parseDouble(mapPartPrice.get("顶针底板").getLength())) / 2;
                    height = constantHeight;
                    break;
                case "模脚2":
                    length = Double.parseDouble(mapPartPrice.get("A板").getLength()) - Double.parseDouble(mapPartPrice.get("模脚1").getWidth()) * 2;
                    width = (Double.parseDouble(mapPartPrice.get("A板").getWidth()) - Double.parseDouble(mapPartPrice.get("顶针底板").getWidth())) / 2;
                    height = constantHeight;
            }
        }
        weight = length * width * height * density;
        Map<String, Double> prams = new HashMap<>();
        prams.put("length", length);
        prams.put("width", width);
        prams.put("height", height);
        prams.put("weight", weight);
        return prams;
    }

    @Override
    public String deleteMoldTypePart(JSONObject jsonObject) {
        //jsonobject解析获取零件Id
        String partId = jsonObject.getString("partId");
        //jsonobject解析获取模具类型Id
        String moldTypeId = jsonObject.getString("moldTypeId");

        int delete = partMoldTypeMapper.delete(
                new LambdaUpdateWrapper<PartMoldType>()
                        .eq(PartMoldType::getPartId, partId)
                        .eq(PartMoldType::getMoldTypeId, moldTypeId));

        if (delete > 0) {
            return JSON.toJSONString(R.success("删除成功"));
        }
        return JSON.toJSONString(R.success("无数据"));
    }
}